import { JXDef } from "../../../conventions/JXCommon";
import GViewBase from "../../../Core/GView/GViewBase";
import MathEx from "../../../Core/Math/MathEx";
import { JXColor } from "../../Common/JXColor";
import GameMgr from "../../Logic/GameMgr";
const { ccclass, property, menu } = cc._decorator;

@ccclass @menu('View/Home/NoticeCtrl')
export default class NoticeCtrl extends GViewBase {
    @property({ type: cc.Node, tooltip: "公告背景" }) notice: cc.Node = null;
    @property({ type: cc.RichText, tooltip: "公告文案" }) noticeRichText: cc.RichText = null;

    start() {
        this.twe();
    }

    twe() {
        let ret: string = `<color=${JXColor.CFFF10B.toHEX()}>${'提示：通过加持中的合成'}</c>` + `<color=${JXColor.Cff0000.toHEX()}>${'强化功能，可以提升装备属性'}</c>`// JXColor.C925600.toHEX()  JXColor.CFF003D.toHEX()
        let index = MathEx.random(1, GameMgr.noticeData.data.values().length);
        ret = GameMgr.noticeData.getRaw<SNoticeDataRaw>(index).txt;
        // var a = ret.replaceAll('\"', "");
        var a = ret.replace(/\"/g, "");
        this.noticeRichText.string = a;
        this.noticeRichText.node.x = 150;
        // console.log(this.noticeRichText.node.x, this.noticeRichText.string);
        let noticeTime: number = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.noticeTime);
        this.scheduleOnce(() => { this.notice.active = false }, 9.1);
        this.scheduleOnce(() => { this.twe(), this.notice.active = true; }, 10.5 + noticeTime);
        cc.tween(this.noticeRichText.node)
            .to(9, { position: cc.v2(-1000, 0) })//初始位置
            .call(() => {

            })
            .union()
            .start()
    }

}
